import axios from 'axios'
import {
  refreshToken
} from './apis'
const newAxios = axios.create({
  baseURL: 'http://127.0.0.1:5000/api/',
  timeout: 5000
})
newAxios.interceptors.request.use(config => {
  console.log(config)
  let token = ''
  if (config.config.url === 'refresh') {
    token = window.sessionStorage.getItem('refresh_token')
  }
  token = window.sessionStorage.getItem('access_token')
  config.headers.Authorization = 'Bearer ' + token
  return config
})
newAxios.interceptors.response.use(response => {
  const mate = response.data.mate
  if (mate.status === 403) {
    refreshToken().then(res => {

    })
  }
  return response
})

export default newAxios
